#include <GUIConstants.au3>
#include <Array.au3>
#include <File.au3>

$answer = MsgBox(4, "BlenderTo2.5", "Blender.  Run?")


; Check the user's answer to the prompt (see the help file for MsgBox return values)
; If "No" was clicked (7) then exit the script
If $answer = 7 Then
    MsgBox(0, "AutoIt", "OK.  Bye!")
    Exit
EndIf

Func ListCreate($nReserved = 10)
    If $nReserved <= 0 Then $nReserved = 10
    Local $a[$nReserved + 1]
    Return $a
EndFunc

Func ListPushBack(ByRef $aList, $vData)
    If UBound($aList) <= $aList[0] Then ReDim $aList[UBound($aList) * 1.5]
    $aList[$aList[0]] = $vData
    $aList[0] += 1
EndFunc

Func ListGetSize(ByRef $aList)
    Return $aList[0]
EndFunc

Func ListGetElement(ByRef $aList, $index)
    Return $aList[$index + 1]
EndFunc



Func GetDirectories($path)
	$FileList= _FileListToArray($path, '*.*', 2)
	For $i = 1 To UBound($FileList)-1
		$FileList[$i] = $path & $FileList[$i] & "\"
	Next
	return $FileList
EndFunc

Func GetFiles($path)
	$FileList= _FileListToArray($path, '*.blend', 1)
	For $i = 1 To UBound($FileList)-1
		$FileList[$i] = $path & $FileList[$i]
	Next
	return $FileList
EndFunc

Func GetBlends(ByRef $list,  $path)
	$dirs=GetDirectories($path)
	For $i = 1 To UBound($dirs)-1
		GetBlends($list,  $dirs[$i])
	Next
	$files=GetFiles($path)
	For $i = 1 To UBound($files)-1
		ListPushBack($list, $files[$i])
	Next
EndFunc

$alist=ListCreate()
GetBlends($alist, "C:\VC\assetserver\tests\workers\test\")
ReDim $aList[$aList[0]]
_ArrayDisplay($alist,"$FileList")

$answer = MsgBox(4, "BlenderTo2.5", "Continue?")
If $answer = 7 Then
	Exit
EndIf


For $i = 1 To UBound($alist)-1
	Run("C:\VC\Freestyle_r31507_Win32\blender.exe " & $alist[$i])
	WinWaitActive("[CLASS:GHOST_WindowClass]")

	Sleep(2000)
	Send("{F12}")
	Sleep(2000)
	Send("{ESC}")
	
	Sleep(500)
	Send("^{s}")
	Sleep(50)
	Send("{ENTER}")
	
	;$answer = MsgBox(4, "BlenderTo2.5", "Continue?")
	;If $answer = 7 Then
	;	Exit
	;EndIf
	
	
	Sleep(500)
	Send("^{q}")
	Sleep(50)
	Send("{ENTER}")
	Sleep(500)
Next

Exit

